/*********************************************************************************
*            (c) Copyright,Shenzhen Smart Drone UAV Co., Ltd.  
*                        All Rights Reserved  
* 
* File 	 : cam_if.c
* By  	 : hirsi
* Date	 :2019-07-31 09:56:10
* Other	 : 
*  
**********************************************************************************/
#include "Sys.h"
#include "app_schd_task.h"
#include "app_cam_ts1.h"
#include "uorb.h"
#include "app_touch_screen.h"


ORB_DEFINE(cam_basic_ctrl_cmd10,CAMCMD10_ST);
ORB_DEFINE(cam_basic_ctrl_cmd11,CAMCMD11_ST);
ORB_DEFINE(cam_basic_ctrl_cmd1e,CAMCMD1E_ST);



#define CMD10_CAM_OFS          1
#define CMD11_CAM_OFS          3


CAMCMD10_ST ahead10,*pcur10; 
CAMCMD11_ST ahead11,*pcur11; 
CAMCMD1E_ST ahead1E,*pcur1E; 


void camif_canrev_isr (INT8U *dt, INT8U len)
{	
	if (dt[0] == 0x10)
	{		
		pcur10 = (CAMCMD10_ST*)(&dt[CMD10_CAM_OFS]);

		orb_publish(ORB_ID(cam_basic_ctrl_cmd10),pcur10);
		
		mem_cpy((INT8U *)&ahead10, pcur10, sizeof(ahead10));
	}
	else if (dt[0] == 0x11)//cmd.
	{ 	
		pcur11 = (CAMCMD11_ST*)(&dt[CMD11_CAM_OFS]);

		orb_publish(ORB_ID(cam_basic_ctrl_cmd11),pcur11);

		mem_cpy((INT8U *)&ahead11, pcur11, sizeof(ahead11));
	}
	else if (dt[0] == 0x1e)// 30
	{ 
		
		pcur1E = (CAMCMD1E_ST*)(&dt[1]);
		
		orb_publish(ORB_ID(cam_basic_ctrl_cmd1e),pcur1E);
		
		mem_cpy((INT8U *)&ahead1E, pcur1E, sizeof(ahead1E));
	}
	else if(dt[0] == 0x16)
	{
		#if DEVICE_TOUCH_SCREEN_ENABLE
		
		touch_screen_t touch_screen_info = {0};
		memcpy(&touch_screen_info,&dt[1],sizeof(touch_screen_info));
		
		orb_publish(ORB_ID(touch_screen_ctrl),&touch_screen_info);
		
		#endif
	}
}

void camif_heart_loop(void)
{
	CAN_sendfifo(DEVICEFLAG_CAM, (uint8_t *)&ahead11, sizeof(ahead11));
	//printf("camif_heart \r\n");
}

void camif_init (void)
{
	mem_set((INT8U *)&ahead10, 0, sizeof(ahead10));
	mem_set((INT8U *)&ahead11, 0, sizeof(ahead11));
	mem_set((INT8U *)&ahead1E, 0, sizeof(ahead1E));

	uint8_t ret = 0;
	ret = orb_advertise(ORB_ID(cam_basic_ctrl_cmd10));
	if(!ret) printf("[%s] advertise error.\r\n","cam_basic_ctrl_cmd10 struct");
	
	ret = orb_advertise(ORB_ID(cam_basic_ctrl_cmd11));
	if(!ret) printf("[%s] advertise error.\r\n","cam_basic_ctrl_cmd11 struct");
	
	ret = orb_advertise(ORB_ID(cam_basic_ctrl_cmd1e));
	if(!ret) printf("[%s] advertise error.\r\n","cam_basic_ctrl_cmd1e struct");

	ahead11.mode = 3;
}




